home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Internet / gpodder / gpodder-3.8.3-setup.exe / {app} / src / mygpoclient / public_test.py < prev    next >
Text File  |  2013-02-08  |  10KB  |  202 lines

  1. # -*- coding: utf-8 -*-
  2. # gpodder.net API Client
  3. # Copyright (C) 2009-2013 Thomas Perl and the gPodder Team
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  
  18. from mygpoclient import public
  19. from mygpoclient import simple
  20. from mygpoclient import testing
  21.  
  22. import unittest
  23.  
  24. class Test_Tag(unittest.TestCase):
  25.     def test_tagFromDict_raisesValueError_missingKey(self):
  26.         self.assertRaises(ValueError,public.Tag.from_dict, {'tag':'abcde'} )
  27.  
  28. class Test_Episode(unittest.TestCase):
  29.     def test_episodeFromDict_raisesValueError_missingKey(self):
  30.         self.assertRaises(ValueError,public.Episode.from_dict, {'title':'foobar','podcast_url':'http://www.podcast.com'})
  31.         
  32. class Test_PublicClient(unittest.TestCase):
  33.     TOPLIST_JSON = """
  34.     [{
  35.     "website": "http://linuxoutlaws.com/podcast", 
  36.     "description": "Open source talk with a serious attitude", 
  37.     "title": "Linux Outlaws", 
  38.     "url": "http://feeds.feedburner.com/linuxoutlaws", 
  39.     "subscribers_last_week": 1736, 
  40.     "subscribers": 1736, 
  41.     "mygpo_link": "http://www.gpodder.net/podcast/11092", 
  42.     "logo_url": "http://linuxoutlaws.com/files/albumart-itunes.jpg"
  43.     }, 
  44.     {
  45.     "website": "http://syndication.mediafly.com/redirect/show/d581e9b773784df7a56f37e1138c037c", 
  46.     "description": "We are not talking dentistry here; FLOSS all about Free Libre Open Source Software. Join hosts Randal Schwartz and Leo Laporte every Saturday as they talk with the most interesting and important people in the Open Source and Free Software community.", 
  47.     "title": "FLOSS Weekly Video (large)", 
  48.     "url": "http://feeds.twit.tv/floss_video_large",
  49.     "subscribers_last_week": 50, 
  50.     "subscribers": 50, 
  51.     "mygpo_link": "http://www.gpodder.net/podcast/31991", 
  52.     "logo_url": "http://static.mediafly.com/publisher/images/06cecab60c784f9d9866f5dcb73227c3/icon-150x150.png"
  53.     }]
  54.     """
  55.     TOPLIST = [
  56.             simple.Podcast('http://feeds.feedburner.com/linuxoutlaws',
  57.                 'Linux Outlaws',
  58.                 'Open source talk with a serious attitude',
  59.                 'http://linuxoutlaws.com/podcast',
  60.                 1736, 1736,
  61.                 'http://www.gpodder.net/podcast/11092',
  62.                 'http://linuxoutlaws.com/files/albumart-itunes.jpg'),
  63.             simple.Podcast('http://feeds.twit.tv/floss_video_large',
  64.                 'FLOSS Weekly Video (large)',
  65.                 'We are not talking dentistry here; FLOSS all about Free Libre Open Source Software. Join hosts Randal Schwartz and Leo Laporte every Saturday as they talk with the most interesting and important people in the Open Source and Free Software community.',
  66.                 'http://syndication.mediafly.com/redirect/show/d581e9b773784df7a56f37e1138c037c',
  67.                 50, 50,
  68.                 'http://www.gpodder.net/podcast/31991',
  69.                 'http://static.mediafly.com/publisher/images/06cecab60c784f9d9866f5dcb73227c3/icon-150x150.png'),
  70.     ]
  71.     SEARCHRESULT_JSON = """
  72.     [{
  73.     "website": "http://linuxoutlaws.com/podcast", 
  74.     "description": "Open source talk with a serious attitude", 
  75.     "title": "Linux Outlaws", 
  76.     "url": "http://feeds.feedburner.com/linuxoutlaws", 
  77.     "subscribers_last_week": 1736, 
  78.     "subscribers": 1736, 
  79.     "mygpo_link": "http://www.gpodder.net/podcast/11092", 
  80.     "logo_url": "http://linuxoutlaws.com/files/albumart-itunes.jpg"
  81.     }, 
  82.     {
  83.     "website": "http://syndication.mediafly.com/redirect/show/d581e9b773784df7a56f37e1138c037c", 
  84.     "description": "We are not talking dentistry here; FLOSS all about Free Libre Open Source Software. Join hosts Randal Schwartz and Leo Laporte every Saturday as they talk with the most interesting and important people in the Open Source and Free Software community.", 
  85.     "title": "FLOSS Weekly Video (large)", 
  86.     "url": "http://feeds.twit.tv/floss_video_large",
  87.     "subscribers_last_week": 50, 
  88.     "subscribers": 50, 
  89.     "mygpo_link": "http://www.gpodder.net/podcast/31991", 
  90.     "logo_url": "http://static.mediafly.com/publisher/images/06cecab60c784f9d9866f5dcb73227c3/icon-150x150.png"
  91.     }]
  92.     """
  93.     SEARCHRESULT = [
  94.             simple.Podcast('http://feeds.feedburner.com/linuxoutlaws',
  95.                 'Linux Outlaws',
  96.                 'Open source talk with a serious attitude',
  97.                 'http://linuxoutlaws.com/podcast',
  98.                 1736, 1736,
  99.                 'http://www.gpodder.net/podcast/11092',
  100.                 'http://linuxoutlaws.com/files/albumart-itunes.jpg'),
  101.             simple.Podcast('http://feeds.twit.tv/floss_video_large',
  102.                 'FLOSS Weekly Video (large)',
  103.                 'We are not talking dentistry here; FLOSS all about Free Libre Open Source Software. Join hosts Randal Schwartz and Leo Laporte every Saturday as they talk with the most interesting and important people in the Open Source and Free Software community.',
  104.                 'http://syndication.mediafly.com/redirect/show/d581e9b773784df7a56f37e1138c037c',
  105.                 50, 50,
  106.                 'http://www.gpodder.net/podcast/31991',
  107.                 'http://static.mediafly.com/publisher/images/06cecab60c784f9d9866f5dcb73227c3/icon-150x150.png'),
  108.     ]
  109.  
  110.     TOPTAGS_JSON = """
  111.     [
  112.         {"tag": "Technology",
  113.          "usage": 530 },
  114.         {"tag": "Arts",
  115.          "usage": 400}
  116.     ]
  117.     """
  118.     TOPTAGS = [
  119.                public.Tag('Technology',530),
  120.                public.Tag('Arts',400)
  121.     ]
  122.     
  123.     PODCAST_JSON = """
  124.     {
  125.     "website": "http://linuxoutlaws.com/podcast", 
  126.     "description": "Open source talk with a serious attitude", 
  127.     "title": "Linux Outlaws", 
  128.     "url": "http://feeds.feedburner.com/linuxoutlaws", 
  129.     "subscribers_last_week": 1736, 
  130.     "subscribers": 1736, 
  131.     "mygpo_link": "http://www.gpodder.net/podcast/11092", 
  132.     "logo_url": "http://linuxoutlaws.com/files/albumart-itunes.jpg"
  133.     }
  134.     """
  135.     PODCAST = simple.Podcast('http://feeds.feedburner.com/linuxoutlaws',
  136.                 'Linux Outlaws',
  137.                 'Open source talk with a serious attitude',
  138.                 'http://linuxoutlaws.com/podcast',
  139.                 1736, 1736,
  140.                 'http://www.gpodder.net/podcast/11092',
  141.                 'http://linuxoutlaws.com/files/albumart-itunes.jpg')
  142.  
  143.     EPISODE_JSON = """
  144.     {"title": "TWiT 245: No Hitler For You",
  145.     "url": "http://www.podtrac.com/pts/redirect.mp3/aolradio.podcast.aol.com/twit/twit0245.mp3",
  146.     "podcast_title": "this WEEK in TECH - MP3 Edition",
  147.     "podcast_url": "http://leo.am/podcasts/twit", 
  148.     "description": "[...]",
  149.     "website": "http://www.podtrac.com/pts/redirect.mp3/aolradio.podcast.aol.com/twit/twit0245.mp3", 
  150.     "released": "2010-12-25T00:30:00",
  151.     "mygpo_link": "http://gpodder.net/episode/1046492"}
  152.     """
  153.     EPISODE = public.Episode('TWiT 245: No Hitler For You',
  154.                              'http://www.podtrac.com/pts/redirect.mp3/aolradio.podcast.aol.com/twit/twit0245.mp3',
  155.                              'this WEEK in TECH - MP3 Edition',
  156.                              'http://leo.am/podcasts/twit',
  157.                              '[...]',
  158.                              'http://www.podtrac.com/pts/redirect.mp3/aolradio.podcast.aol.com/twit/twit0245.mp3',
  159.                              '2010-12-25T00:30:00',
  160.                              'http://gpodder.net/episode/1046492'
  161.                              )
  162.  
  163.     def setUp(self):
  164.         self.fake_client = testing.FakeJsonClient()
  165.         self.client = public.PublicClient(client_class=self.fake_client)
  166.  
  167.     def test_getToplist(self):
  168.         self.fake_client.response_value = self.TOPLIST_JSON
  169.         result = self.client.get_toplist()
  170.         self.assertEquals(result, self.TOPLIST)
  171.         self.assertEquals(len(self.fake_client.requests), 1)
  172.  
  173.     def test_searchPodcasts(self):
  174.         self.fake_client.response_value = self.SEARCHRESULT_JSON
  175.         result = self.client.search_podcasts('wicked')
  176.         self.assertEquals(result, self.SEARCHRESULT)
  177.         self.assertEquals(len(self.fake_client.requests), 1)
  178.         
  179.     def test_getPodcastsOfATag(self):
  180.         self.fake_client.response_value = self.SEARCHRESULT_JSON
  181.         result = self.client.get_podcasts_of_a_tag('wicked')
  182.         self.assertEquals(result, self.SEARCHRESULT)
  183.         self.assertEquals(len(self.fake_client.requests), 1)
  184.  
  185.     def test_getTopTags(self):
  186.         self.fake_client.response_value = self.TOPTAGS_JSON
  187.         result = self.client.get_toptags()
  188.         self.assertEquals(result, self.TOPTAGS)
  189.         self.assertEquals(len(self.fake_client.requests), 1)
  190.         
  191.     def test_getPodcastData(self):
  192.         self.fake_client.response_value = self.PODCAST_JSON
  193.         result = self.client.get_podcast_data('http://feeds.feedburner.com/linuxoutlaws')
  194.         self.assertEquals(result, self.PODCAST)
  195.         self.assertEquals(len(self.fake_client.requests), 1)
  196.         
  197.     def test_getEpisodeData(self):
  198.         self.fake_client.response_value = self.EPISODE_JSON
  199.         result = self.client.get_episode_data('http://leo.am/podcasts/twit','http://www.podtrac.com/pts/redirect.mp3/aolradio.podcast.aol.com/twit/twit0245.mp3')
  200.         self.assertEquals(result, self.EPISODE)
  201.         self.assertEquals(len(self.fake_client.requests), 1)
  202.